package Person;

import java.util.List;
/**
 * @Author: Cjj
 * 过滤器模式
 *  这种模式允许开发人员使用不同的标准来过滤一组对象,通过逻辑运算以解耦的方式把它们连接起来
 *  这种类型的设计模式属于结构型模式,它结合多个标准来获得单一标准
 */
public class OrCriteria implements Criteria{
    private Criteria criteria;
    private Criteria otherCriteria;
    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> meetCriteria = criteria.meetCriteria(persons);
        return meetCriteria;
    }
public OrCriteria(Criteria criteria,Criteria otherCriteria){
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;

}

public List<Person> meetCriter(List<Person> persons) {
        List<Person> firstCriteriaItems = criteria.meetCriteria(persons);
        List<Person> otherCriteriaItems = otherCriteria.meetCriteria(persons);
        for (Person person : otherCriteriaItems) {
            if(!firstCriteriaItems.contains(person)){
                firstCriteriaItems.add(person);
            }
        }
        return firstCriteriaItems;
}

}
